<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <input type="button" value="开始计时" class="input" onclick="startTime()"><br />
    <input type="button" value="停止计时" onclick="stopTime()">
    <span>现在时间是：</span>
    <span id="demo"></span>
    <script>

        var a;
        function startTime() {
            a = setInterval("showTime()", 1000);
        }
        function showTime() {
            var d = new Date();
            var y = d.getFullYear();
            var m = d.getMonth() + 1;
            var dat = d.getDate();
            var h = d.getHours();
            var M = d.getMinutes();
            var s = d.getSeconds();
            document.querySelector('#demo').innerHTML
                = y + '年' + m + '月' + dat + '日' + h + ':' + M + ':' + s;
            // document.getElementById('001')
        }
        function stopTime() {
            clearInterval(a);
        }
    </script>
</body>

</html>